window.onload = function() {
  tabPage({
    pageMain: 'pageMain',
    pageNav: 'pageNav',
    pagePrev: 'prev',
    pageNext: 'next',
    curNum: 3,
    activeClass: 'active',
    ini: 0
  });
  
  function tabPage(tabPage) {
    var pageMain = document.getElementById(tabPage.pageMain);
    var pageNav = document.getElementById(tabPage.pageNav);
    var pagePrev = document.getElementById(tabPage.pagePrev);
    var pageNext = document.getElementById(tabPage.pageNext);
  
    var curNum = tabPage.curNum;
    var len = Math.ceil(pageMain.children.length / curNum);
    var pageList = '';
    var iNum = 0;
  
    for (var index = 0; index < len; index++) {
      pageList += '<a href="javascript:;">' + (index + 1) + '</a>';
    }
    pageNav.innerHTML = pageList;
  
    pageNav.children[0].className = tabPage.activeClass;
  
    for (var index = 0; index < pageNav.children.length; index++) {
      pageNav.children[index].index = index;
      pageNav.children[index].onclick = function() {
        for (var t = 0; t < pageNav.children.length; t++) {
          pageNav.children[t].className = '';
        }
        this.className = tabPage.activeClass;
        iNum = this.index;
        ini(iNum);
      };
    }
  
  
    //下一页
    pageNext.onclick = function() {
      if (iNum == len - 1) {
        alert('已经是最后一页');
        return false;
      } else {
        for (var t = 0; t < pageNav.children.length; t++) {
          pageNav.children[t].className = '';
        }
        iNum++;
        pageNav.children[iNum].className = tabPage.activeClass;
        ini(iNum);
      }
    };
  
    //上一页
    pagePrev.onclick = function() {
      if (iNum == 0) {
        alert('当前是第一页');
        return false;
      } else {
        for (var t = 0; t < pageNav.children.length; t++) {
          pageNav.children[t].className = '';
        }
        iNum--;
        pageNav.children[iNum].className = tabPage.activeClass;
        ini(iNum);
      }
    };
  
    function ini(iNum) {
      for (var index = 0; index < pageMain.children.length; index++) {
        pageMain.children[index].style.display = 'none';
      }
  
      for (var index = 0; index < curNum; index++) {
        if (pageMain.children[(iNum * curNum + index)] == undefined) {
          break;
        }
        pageMain.children[(iNum * curNum + index)].style.display = 'block';
      }
    }
    ini(iNum);
  }
};